package com.tank.action.itemsObjct;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.tank.bean.User;
import com.tank.bean.item.Product;
import com.tank.dao.UserDAO;
import com.tank.service.ItemsManageService;
import com.tank.util.TankUtil;

public class ItemsProfileAction extends ActionSupport{
	
	private Integer userId;
	private Integer cuUserId;
	private User user;
	private User cuUser;
	private List<Product> productJd;
	private List<Product> productFs;
	private List<Product> productWt;
	private List<Product> productJj;
	private List<Product> productQt;
	private int itemsCount;
	
	@Autowired
	private ItemsManageService itemsManageService;
	@Autowired
	private UserDAO userDao;
	
	@Override
	public String execute() throws Exception {
		cuUser = TankUtil.getCurrentUser();
		cuUserId = cuUser.getId();
		System.out.println("userId==="+userId);
		System.out.println("cuUserId==="+cuUserId);
		System.out.println((long)userId==(long)cuUserId);
		if(userId!=null && userId!=0){
			if((long)userId==(long)cuUserId){
				user = cuUser;
				productJd = itemsManageService.queryItems(cuUserId, 1);
				productFs = itemsManageService.queryItems(cuUserId, 2);
				productWt = itemsManageService.queryItems(cuUserId, 3);
				productJj = itemsManageService.queryItems(cuUserId, 4);
				productQt = itemsManageService.queryItems(cuUserId, 5);
				itemsCount = productJd.size()+productFs.size()+productWt.size()+productJj.size()+productQt.size();
				return "success";
			}else{
				user = userDao.findUserById(userId);
				productJd = itemsManageService.queryItems(userId, 1);
				productFs = itemsManageService.queryItems(userId, 2);
				productWt = itemsManageService.queryItems(userId, 3);
				productJj = itemsManageService.queryItems(userId, 4);
				productQt = itemsManageService.queryItems(userId, 5);
				itemsCount = productJd.size()+productFs.size()+productWt.size()+productJj.size()+productQt.size();
				return "otherItem";
			}
		}else{
			user = cuUser;
			productJd = itemsManageService.queryItems(cuUserId, 1);
			productFs = itemsManageService.queryItems(cuUserId, 2);
			productWt = itemsManageService.queryItems(cuUserId, 3);
			productJj = itemsManageService.queryItems(cuUserId, 4);
			productQt = itemsManageService.queryItems(cuUserId, 5);
			itemsCount = productJd.size()+productFs.size()+productWt.size()+productJj.size()+productQt.size();
			return "success";
		}
		
		
	}

	
	public Integer getUserId() {
		return userId;
	}


	public void setUserId(Integer userId) {
		this.userId = userId;
	}


	public List<Product> getProductJd() {
		return productJd;
	}

	public void setProductJd(List<Product> productJd) {
		this.productJd = productJd;
	}

	public List<Product> getProductFs() {
		return productFs;
	}

	public void setProductFs(List<Product> productFs) {
		this.productFs = productFs;
	}

	public List<Product> getProductWt() {
		return productWt;
	}

	public void setProductWt(List<Product> productWt) {
		this.productWt = productWt;
	}

	public List<Product> getProductJj() {
		return productJj;
	}

	public void setProductJj(List<Product> productJj) {
		this.productJj = productJj;
	}

	public List<Product> getProductQt() {
		return productQt;
	}

	public void setProductQt(List<Product> productQt) {
		this.productQt = productQt;
	}

	public Integer getCuUserId() {
		return cuUserId;
	}

	public void setCuUserId(Integer cuUserId) {
		this.cuUserId = cuUserId;
	}


	public User getCuUser() {
		return cuUser;
	}


	public void setCuUser(User cuUser) {
		this.cuUser = cuUser;
	}


	public int getItemsCount() {
		return itemsCount;
	}


	public void setItemsCount(int itemsCount) {
		this.itemsCount = itemsCount;
	}


	public User getUser() {
		return user;
	}


	public void setUser(User user) {
		this.user = user;
	}
	
	
}
